<?php
/**
 * Login_Data_Loggeddatacheckout
 * @author Adrian Stolarski
 */
class Login_Data_Loggeddatacheckout implements Login_Data_Mainable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    
    /**
     *
     * @var type $database_query
     */
    public $database_query;
    
    /**
     * constructor()
     */
    public function __construct(){
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * check user data
     * @param array $variables
     * @return type user_id
     */
    public function main(array $variables = null) {
        //var_dump($variables);
        $this->database->connect();
        //var_dump($variables);
        foreach($variables as $key => $value){
            //var_dump($variables);
            $variables[$key] = $this->database->escape($value);
        }
        //var_dump($variables);
        $this->database_query = "SELECT id FROM users_data WHERE user_email='".$variables['user_email']."' AND user_password='".md5($variables['user_password'])."' LIMIT 1;";
        $this->database->prepare($this->database_query);
        $this->database->query();
        $user_data = $this->database->fetch('array');
        //var_dump($user_data);
        $user_id = $user_data['id'];
        return $user_id;
    }
}
